<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="股票" >
        <el-input
            v-model="queryParams.instrument"
            placeholder="请输入股票"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" size="small" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="small"
            @click="handleExport"
            v-hasPermi="['marketdata:equity:shares:sharesInfo:export']"
        >当页导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            size="small"
            @click="handleExportAll"
            v-hasPermi="['marketdata:equity:shares:sharesInfo:export']"
        >全量导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table stripe="true" v-loading="loading" :data="sharesBonusList" >
      <el-table-column type="selection" width="45" align="center" />
      <el-table-column label="序号" type="index"  width="60"/>
      <el-table-column label="股票代码" align="center" prop="iCode" />
      <el-table-column label="资产类型" align="center" prop="aType" >
        <template #default="scope">
          <dict-tag :options="A_TYPE" :value="scope.row.aType" />
        </template>
      </el-table-column>
      <el-table-column label="市场类型" align="center" :show-overflow-tooltip="true"  prop="mType" >
        <template #default="scope">
          <dict-tag :options="M_TYPE" :value="scope.row.mType" />
        </template>
      </el-table-column>
      <el-table-column label="股票名称" align="center" :show-overflow-tooltip="true" prop="sName"> </el-table-column>
      <el-table-column label="每股分红(元)" align="right" prop="sDividend" :formatter="formartTableP2" />
      <el-table-column label="每股送股(股)" align="right" prop="sSplitRatio" :formatter="formartTableP2"> </el-table-column>
      <el-table-column label="配股比例" align="right" prop="sQuotaRatio" :formatter="formartTableP4" />
      <el-table-column label="配股价格" align="right" prop="sQuotaPrice" :formatter="formartTableP2" />
      <el-table-column label="权益登记日" align="center" prop="sCheckDate" />
      <el-table-column label="除权除息日" align="center" prop="sExecDate" />
      <el-table-column label="公告日期" align="center" prop="sPublishDate" />
    </el-table>
    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script setup name="sharesBonus">
import {getSharesBonusList } from "@/api/marketdata/equity/shares";

const { proxy } = getCurrentInstance();
const { M_TYPE } = proxy.useDict("M_TYPE");
const { A_TYPE } = proxy.useDict("A_TYPE");
const { CURRENCY } = proxy.useDict("CURRENCY");

const sharesBonusList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 20,
    instrument: undefined
  }
});

const { queryParams } = toRefs(data);

/** 查询列表 */
function getList() {
  loading.value = true;
  getSharesBonusList(queryParams.value).then(response => {
    sharesBonusList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}



/** 导出按钮操作 */
function handleExport() {
  proxy.download("marketdata/stockController/exportBonus", {
    ...queryParams.value
  }, `股票分红信息${new Date().getTime()}.xlsx`);
}

/** 导出按钮操作 */
function handleExportAll() {
  proxy.download("marketdata/stockController/export", Object.assign({
    ...queryParams.value
  },{pageSize:''}), `股票分红信息${new Date().getTime()}.xlsx`);
}
getList();
</script>
